<?php
namespace Home\Controller;
use Think\Controller;
class ProtocolController extends Controller {
    public function customerSignUp() {
        $this->display();
    }

    public function merchantSignUp() {
        $this->display();
    }

    public function order() {
       /* $customer_id = $_REQUEST['customer_id'];
//         $customer_id = 2162;
//        $amount = $_REQUEST['amount'];
        $amount = M("Customer")->where("id=".$customer_id)->getField('cash_amount');
        $repay_time = $_REQUEST['repay_time'];
        $id_num = M("Customer")->where("id=".$customer_id)->getField('id_num');
        $real_name = M("Customer")->where("id=".$customer_id)->getField('real_name');
        $conInfo = M("ConsumeHistory")->where("customer_id=".$customer_id)->order("add_time DESC")->select();
        $repayId = $conInfo[0]['repay_id']; //成单的时候有repay_id
        $cash_conf = M('SysInstallmentPlan')->where(['publish' => 1, 'target' => 3, 'id'=>$repayId])->select();
        $chooseProduct = $cash_conf[0];
        $chooseP = D('Finish')->getWithdrawalDetail($conInfo[0]['amount'], $chooseProduct, $chooseProduct['repay_unit']);
        $rate = ($amount*0.0375)/100;//每期管理费
        $tou = ceil($amount*0.12*0.01);
        if($cash_conf[0]['timer']==14){
            $feeAmount=ceil($amount*0.12*0.01);
        }elseif($cash_conf[0]['timer']==30){
            $feeAmount=ceil($amount*0.2*0.01);
        }
        $this->assign("borrowdays", $cash_conf[0]['timer']);
        $this->assign('now',date("Y-m-d H:i:s",time()));
        $this->assign('now1',date("Y年m月d日",time()));
        $this->assign('id_num',$id_num);
        $this->assign('real_name',$real_name);
        $this->assign('amount',$amount*0.01);
        $this->assign('tou',$tou);
        $this->assign('rate',$rate);
        $this->assign('No',$conInfo[0]['add_time']);
//        $this->assign('amount',$conInfo[0]['amount']*0.01);
//        $this->assign('Mamount',$chooseP['feeAmount']*0.01);
        $this->assign('Mamount',$feeAmount);
        $this->assign('repay_time',$repay_time);
        $this->display();*/
        $customer_id = $_REQUEST['customer_id'];
//         $customer_id = 2162;
        //$amount = $_REQUEST['amount'];
        $amount = M("Customer")->where("id=".$customer_id)->getField('cash_amount');
        $amount=$amount*0.01;
        $repay_time = $_REQUEST['repay_time'];
        $id_num = M("Customer")->where("id=".$customer_id)->getField('id_num');
        $real_name = M("Customer")->where("id=".$customer_id)->getField('real_name');
        $conInfo = M("ConsumeHistory")->where("customer_id=".$customer_id)->order("add_time DESC")->select();
        $repayId = $conInfo[0]['repay_id']; //成单的时候有repay_id
        $cash_conf = M('SysInstallmentPlan')->where(['publish' => 1, 'target' => 3, 'id'=>$repayId])->select();
        $chooseProduct = $cash_conf[0];
        $chooseP = D('Finish')->getWithdrawalDetail($conInfo[0]['amount'], $chooseProduct, $chooseProduct['repay_unit']);
        $rate = ($amount*0.0375)/100;//每期管理费
        $tou = ceil($amount*0.12*0.01);
        /*服务费*/
        $server_fee=$amount*$cash_conf[0]['cut_interest'];
        /*服务费*/
        $this->assign("borrowdays", $cash_conf[0]['timer']);
        $this->assign('now',date("Y-m-d H:i:s",time()));
        $this->assign('now1',date("Y年m月d日",time()));
        $this->assign('id_num',$id_num);
        $this->assign('real_name',$real_name);
        $this->assign('amount',$amount);
        $this->assign('tou',$tou);
        $this->assign('rate',$rate);
        $this->assign('No',$conInfo[0]['add_time']);
       // $this->assign('amount',$conInfo[0]['amount']*0.01);
        $this->assign('Mamount',$server_fee);
       // $this->assign('Mamount',$chooseP['feeAmount']*0.01);
        $this->assign('repay_time',$repay_time);
        $this->display();
    }

    //借款协议
    public function borrowProtocol(){
        $customer_id = $_REQUEST['customer_id'];
//         $customer_id = 2162;
        $amount = $_REQUEST['amount'];
        $repay_time = $_REQUEST['repay_time'];
        $id_num = M("Customer")->where("id=".$customer_id)->getField('id_num');
        $real_name = M("Customer")->where("id=".$customer_id)->getField('real_name');
        $conInfo = M("ConsumeHistory")->where("customer_id=".$customer_id)->order("add_time DESC")->select();
        $repayId = $conInfo[0]['repay_id']; //成单的时候有repay_id
        $cash_conf = M('SysInstallmentPlan')->where(['publish' => 1, 'target' => 3, 'id'=>$repayId])->select();
        $chooseProduct = $cash_conf[0];
        $chooseP = D('Finish')->getWithdrawalDetail($conInfo[0]['amount'], $chooseProduct, $chooseProduct['repay_unit']);
        $rate = ($amount*0.0375)/100;//每期管理费
        $tou = ceil($amount*0.12*0.01);

        $this->assign("borrowdays", $cash_conf[0]['timer']);
        $this->assign('now',date("Y-m-d H:i:s",time()));
        $this->assign('now1',date("Y年m月d日",time()));
        $this->assign('id_num',$id_num);
        $this->assign('real_name',$real_name);
        $this->assign('amount',$amount);
        $this->assign('tou',$tou);
        $this->assign('rate',$rate);
        $this->assign('No',$conInfo[0]['add_time']);
        $this->assign('amount',$conInfo[0]['amount']*0.01);
        $this->assign('Mamount',$chooseP['feeAmount']*0.01);
        $this->assign('repay_time',$repay_time);
        $this->display();
    }
    
}